﻿@{
    ViewBag.Title = "菜单关联功能";
}
<div class="container">
    <div class="panel panel-primary">
        <div class="panel-body form-inline">
            <label>功能ID/功能名称：<input id="sch_keyword" type="text" style="width: 120px;" /></label>
            @Html.MyButton("btn_sch", "搜索")
            @Html.MyButton("btn_choose", "关联功能", "primary")
            @Html.MyButton("btn_fnmanage", "功能管理", "info")
        </div>

        <table id="maingrid"></table>
        <div class="panel-footer">
            <ul id="page1"></ul>
        </div>
    </div>
</div>
@section script
{

    <script src="@Url.Content("~/Scripts/plugins/bootstrap-paginator.min.js")"></script>
    <script src="@Url.Content("~/Scripts/plugins/jquery.grid.js")"></script>

    <script type="text/javascript">
        $(function () {

            var menuid = '@(ViewBag.MENUID)';

            $("#btn_sch").click(function () {
                sch();
            });

            $("#sch_keyword").bind("keydown", function (evt) {
                var e = evt || widows.event;
                if (e.keyCode == "13") {
                    sch();
                }
            });

            $("#btn_choose").click(function () {
                var row = $("#maingrid").bootgrid("getGridSelRow");
                if (row) {
                    saveResult(row.GN_ID);
                }
            });

            $("#btn_fnmanage").click(function () {
                mainfn.window("/xt/function", {
                    title: "小窗口修改功能数据",
                    buttons: [
                    {
                        text: "关闭",
                        handler: function () {
                            sch();
                            mainfn.window("close");
                        }
                    }],
                    onclose: sch
                });
            });

            function saveResult(fnid) {
                $.post("/xt/savemenulinktofunction", { menuid: menuid, fnid: fnid }, function (data) {
                    mainfn.msg(data.msg);
                });
            }

            function sch() {
                $("#maingrid").bootgrid("setGridParam", { sch_keyword: $("#sch_keyword").val() });
                $("#maingrid").bootgrid("reloadGrid", { page: 1 });
            }

            function init(parameters) {

                $("#maingrid").bootgrid({
                    url: '/xt/fnlist',
                    pager: "page1",
                    headers: ["功能ID", "功能名称", "CONTROLLER", "ACTION", "JXM"],
                    cols: [
                        { id: 'GN_ID' },
                        { id: 'GN_MC' },
                        { id: 'GN_CONTROLLER' },
                        { id: 'GN_ACTION' },
                        { id: 'JXM', hidden: true }
                    ],
                    ondbclick: function (e, id, row) {
                        saveResult(id);
                    }
                });

            }

            init();
        });
    </script>
}